package com.hsc.yalebao.volley;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.http.AppConstants;
import com.hsc.yalebao.model.UserBaseBean;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ApiClientVolley {
    private String apiUrl = "";
    private Context mContext;
    private Map<String, String> map;
    private Integer timeout = Integer.valueOf(20000);

    public ApiClientVolley(Context paramContext) {
        this.mContext = paramContext;
    }

    public ApiClientVolley(Context paramContext, String paramString, Map<String, String> paramMap) {
        if (paramString != null)
            this.apiUrl = paramString;
        this.map = paramMap;
        this.mContext = paramContext;
    }

    public void getDotaByVolley(final Handler paramHandler, String paramString1, final int paramInt, final String paramString2, final Map<String, String> paramMap, String paramString3) {
        StringRequest local3 = new StringRequest(0, paramString3, new Response.Listener() {
            public void onResponse(String paramAnonymousString) {
                Log.e("TAG-data", paramAnonymousString);
                if ((paramAnonymousString == null) || (paramAnonymousString.equals(""))) {
                    paramAnonymousString = "{\"msg\":\"请检查网络\",\"flag\":\"100\"}";
                    Log.e("TAG-data:null", paramAnonymousString);
                }
                Message localMessage = new Message();
                Bundle localBundle = new Bundle();
                localBundle.putString("data", paramAnonymousString);
                localMessage.setData(localBundle);
                localMessage.obj = paramMap;
                localMessage.what = paramInt;
                paramHandler.sendMessage(localMessage);
            }
        }
                , new Response.ErrorListener() {
            public void onErrorResponse(VolleyError paramAnonymousVolleyError) {
                Log.e("VolleyError", paramAnonymousVolleyError);
                Message localMessage = new Message();
                Bundle localBundle = new Bundle();
                localBundle.putString("data", "{\"msg\":\"请检查网络\",\"flag\":\"100\"}");
                localMessage.setData(localBundle);
                localMessage.what = paramInt;
                paramHandler.sendMessage(localMessage);
            }
        }) {
            public Map<String, String> getHeaders()
                    throws AuthFailureError {
                HashMap localHashMap = new HashMap();
                if (CustomApplication.app.userBaseBean != null) {
                    String str1 = CustomApplication.app.userBaseBean.memberid;
                    String str2 = CustomApplication.app.userBaseBean.getSessionToken();
                    String str3 = CustomApplication.app.userBaseBean.getAccessToken();
                    localHashMap.put("accessToken", str3);
                    localHashMap.put("Session-Token", str1 + "|" + str2);
                    localHashMap.put("Authorization", "Bearer " + str3);
                }
                if (paramString2.equals(AppConstants.URL_GET_NEWWEXINLOGIN))
                    localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
                return localHashMap;
            }

            protected Map<String, String> getParams()
                    throws AuthFailureError {
                return paramMap;
            }
        };
        local3.setRetryPolicy(new DefaultRetryPolicy(50000, 0, 1.0F) {
            public int getCurrentRetryCount() {
                return 2;
            }
        });
        local3.setTag(paramString1);
        CustomApplication.getInstance().getRequestQueue().add(local3);
    }

    public Integer getTimeout() {
        return this.timeout;
    }

    public String getUrlParams(Map<String, String> paramMap) {
        String str1 = "";
        int i;
        Iterator localIterator;
        if ((paramMap != null) && (!paramMap.isEmpty())) {
            i = 0;
            localIterator = paramMap.entrySet().iterator();
            if (localIterator.hasNext()) ;
        } else {
            return str1;
        }
        Map.Entry localEntry = (Map.Entry) localIterator.next();
        String str2 = (String) localEntry.getValue();
        if (Pattern.compile("[一-龥]").matcher(str2).find()) ;
        while (true) {
            try {
                String str4 = URLEncoder.encode(str2, "UTF-8");
                str3 = str4;
                if (i != 0)
                    break label161;
                str1 = (String) localEntry.getKey() + "=" + str3;
                i++;
            } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
                localUnsupportedEncodingException.printStackTrace();
                str3 = str2;
                continue;
            }
            String str3 = str2;
            continue;
            label161:
            str1 = str1 + "&" + (String) localEntry.getKey() + "=" + str3;
        }
    }

    public boolean send(Handler paramHandler, String paramString1, int paramInt, Map<String, String> paramMap, Context paramContext, String paramString2) {
        if ((paramMap == null) || (paramMap.isEmpty())) ;
        String str2;
        for (String str1 = AppConstants.BASE_URL + paramString2; ; str1 = AppConstants.BASE_URL + paramString2 + "?" + str2) {
            getDotaByVolley(paramHandler, paramString1, paramInt, paramString2, paramMap, str1);
            return true;
            str2 = getUrlParams(paramMap);
        }
    }

    public void setTimeout(Integer paramInteger) {
        this.timeout = paramInteger;
    }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.volley.ApiClientVolley
 * JD-Core Version:    0.6.2
 */